<?php
namespace Shoptaepc\Model;
use Think\Model;
class ToolsStatusModel {
	public $curtool;
	public $dicescfg;
	public function getToolCfg(){
		$CHKT = D("Shopadmin/CheckTools");
		$toolid = $CHKT->GetToolID($this->curtool);
		$re = $this->where(Array("sid"=>$this->sid,"tool_id"=>$toolid))->getField("cfg");
		if($re){
			$dicescfg = json_decode($re,true);
		}
		if(!$re || $dicescfg["onoff"]==0){
			$dicescfg = json_decode(C("DICES_DEFAULT"),true);
			foreach($dicescfg["giftset"] as $k=>$d){
				foreach($gifts as $j=>$gift){
					if($gifts[$j]["level"]=="一等奖"&&$k==2){
						$dicescfg["giftset"][$k]["gift"]=$j;
					}elseif($gifts[$j]["level"]=="二等奖"&&$k==4){
						$dicescfg["giftset"][$k]["gift"]=$j;
					}elseif($gifts[$j]["level"]=="三等奖"&&$k==10){
						$dicescfg["giftset"][$k]["gift"]=$j;
					}elseif($gifts[$j]["level"]=="鼓励奖"&&$k==8){
						$dicescfg["giftset"][$k]["gift"]=$j;
					}elseif($gifts[$j]["level"]==""&&($k==13||$k==6)){
						$dicescfg["giftset"][$k]["gift"]=$j;
					}
				}
			}
		}
		$i = 0;
		foreach($dicescfg["giftset"] as $k=>$c){
			if($c["forbidden"]==false){
				$i++;
			}else{
				unset($dicescfg["giftset"][$k]);
			}
		}
		$dicescfg["giftset"]=array_merge($dicescfg["giftset"]);//重设数组下标
		$dicescfg["count"]=$i;
		$this->dicescfg=$dicescfg;
	}
}